/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.partaljevic.gambling.beans;

import com.partaljevic.gambling.Customer;
import com.partaljevic.gambling.Identifiable;
import com.partaljevic.gambling.Privilege;
import java.io.Serializable;
import javax.persistence.Entity;
import java.util.LinkedList;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;

/**
 *
 * @author Danilo
 */
@Entity
public class CustomerBean implements Customer, Identifiable, Serializable {

    @Basic
    private String username;
    @Basic
    private String password;
    @Basic
    private double score;
    @Basic
    private String email;
    @Basic
    private String name;
    @Basic
    private String surname;
    @Basic
    private Privilege privilege;
    @Id
    @GeneratedValue
    private Long id;

    @Override
    public void setScore(double score) {
        this.score = score;
    }
    @OneToMany(targetEntity=Ticket.class, mappedBy="customer", fetch=FetchType.EAGER)
    private List<Ticket> tickets;

    @Override
    public List<Ticket> getWinner(){
        List<Ticket> win = new LinkedList<Ticket>();
        for (Ticket ticket : tickets) {
            if(ticket.isWinner())win.add(ticket);
        }
        return win;
    }

    @Override
    public List<Ticket> getTickets() {
        return tickets;
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public double getScore() {
        return score;
    }

    @Override
    public String getUsername() {
        return username;
    }

    public CustomerBean(String username, String password) {
        this.username = username;
        this.password = password;
        score = 1000;
        tickets = new LinkedList<Ticket>();
        privilege = Privilege.CUSTOMER;
    }

    public CustomerBean() {
        score = 1000;
        tickets = new LinkedList<Ticket>();
        privilege = Privilege.CUSTOMER;
    }

    @Override
    public void addTicket(Ticket ticket) {
        tickets.add(ticket);
    }

    @Override
    public void clearTicket() {
        tickets.clear();
    }

    @Override
    public String showCustomer() {
        return surname+" "+name+ "("+username+")";
    }

    @Override
    public String toString() {
        return username + "\t" + score;
    }

    @Override
    public void setUsername(String username) {
        this.username = username;
    }

    @Override
    public void setPassword(String password) {
        this.password = password;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getId() {
        return id;
    }

    @Override
    public long getID() {
        return id;
    }

    @Override
    public void setPrivilege(Privilege privilege) {
        this.privilege = privilege;
    }

    @Override
    public Privilege getPrivilege() {
        return privilege;
    }

    /**
     * @return the email
     */
    @Override
    public String getEmail() {
        return email;
    }

    /**
     * @param email the email to set
     */
    @Override
    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * @return the name
     */
    @Override
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    @Override
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the surname
     */
    @Override
    public String getSurname() {
        return surname;
    }

    /**
     * @param surname the surname to set
     */
    @Override
    public void setSurname(String surname) {
        this.surname = surname;
    }

    
}
